package com.bayihouse.model.vo;

import com.baomidou.mybatisplus.annotation.TableId;
import com.bayihouse.model.entity.Rentinfo;
import com.bayihouse.utils.MyDateUtils;
import com.google.gson.Gson;
import lombok.Data;
import org.python.google.common.reflect.TypeToken;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Data
public class RentinfoVO implements Serializable {
    private static final long serialVersionUID = -6171304650316977749L;

    /**
     * 租房信息Id
     */
    private Long id;

    /**
     * 租房价格
     */
    private Integer price;

    /**
     * 房子的地址
     */
    private String address;

    /**
     * 房子展示图
     */
    private List<String> displayUrls;

    /**
     * 详情
     */
    private String detail;

    /**
     * 房东名字
     */
    private String landlordname;

    /**
     * 房东电话
     */
    private String landlordtelephone;

    /**
     * 创建时间
     */
    private String createtime;

    /**
     * 0-表示已租房 1-表示未租房
     */
    private String status;

    /**
     * 房屋Id
     */
    private Long roomId;

    private List<Long> occupantIds;

    public static RentinfoVO objToVo(Rentinfo rentinfo) {
        RentinfoVO rentinfoVO = new RentinfoVO();
        BeanUtils.copyProperties(rentinfo, rentinfoVO);
        rentinfoVO.setCreatetime(MyDateUtils.dateToString(rentinfo.getCreatetime()));
        rentinfoVO.setStatus(rentinfo.getStatus() == 1 ? "已租房" : "未租房");
        Gson gson = new Gson();
        if (rentinfo.getOccupantIds() == null) {
            rentinfoVO.setOccupantIds(new ArrayList<>());
        } else {
            rentinfoVO.setOccupantIds(gson.fromJson(rentinfo.getOccupantIds(), new TypeToken<List<Long>>() {
            }.getType()));
        }
        return rentinfoVO;
    }
}
